package com.example.seataOrder.controller;

import com.example.seataOrder.common.response.ObjectResponse;
import com.example.seataOrder.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    private final OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 创建订单接口
     *
     * @param userId        用户ID
     * @param commodityCode 产品编号
     * @param count         商品数量
     * @param orderMoney    订单总金额
     */
    @PostMapping
    @ResponseBody
    public ObjectResponse<Object> createOrder(@RequestParam("userId") String userId,
                                      @RequestParam("commodityCode") String commodityCode,
                                      @RequestParam("count") Integer count,
                                      @RequestParam("orderMoney") Double orderMoney) {
        log.info("参数userId是：{},参数commodityCode是：{},参数count是：{},参数orderMoney是：{}", userId, commodityCode, count, orderMoney);
        return orderService.createOrder(userId, commodityCode, count, orderMoney);
    }
}
